package com.example.dwr.reverse;

import java.util.Date;
import jsx3.GI;
import jsx3.app.Server;
import jsx3.gui.Block;
import jsx3.gui.Button;
import jsx3.gui.ColorPicker;
import jsx3.gui.DatePicker;
import jsx3.gui.Select;
import jsx3.gui.Slider;
import jsx3.gui.TextBox;
import org.directwebremoting.Browser;
import org.directwebremoting.ServerContext;
import org.directwebremoting.ServerContextFactory;

public class Reverse
{
  public void buttonEnable()
  {
    ((Button)getServer().getJSX("button", Button.class)).setEnabled(1, true);
  }

  public void buttonDisable()
  {
    ((Button)getServer().getJSX("button", Button.class)).setEnabled(0, true);
  }

  public void select(String index)
  {
    ((Select)getServer().getJSX("select", Select.class)).setValue(index);
  }

  public void slide(int position)
  {
    ((Slider)getServer().getJSX("slider", Slider.class)).setValue(Integer.valueOf(position));
  }

  public void text(String message)
  {
    ((TextBox)getServer().getJSX("textbox", TextBox.class)).setValue(message);
  }

  public void textEnable()
  {
    ((TextBox)getServer().getJSX("textbox", TextBox.class)).setEnabled(1, true);
  }

  public void textDisable()
  {
    ((TextBox)getServer().getJSX("textbox", TextBox.class)).setEnabled(0, true);
  }

  public void dateToday()
  {
    ((DatePicker)getServer().getJSX("datePicker", DatePicker.class)).setDate(new Date());
  }

  public void dateEpoch()
  {
    ((DatePicker)getServer().getJSX("datePicker", DatePicker.class)).setDate(new Date(0L));
  }

  public void color(String color)
  {
    ((ColorPicker)getServer().getJSX("colorPicker", ColorPicker.class)).setValue(color);
  }

  public void create()
  {
    Button button = new Button("createCreated", 0, 0, 300, "Created Button");
    ((Block)getServer().getJSX("blockCreate", Block.class)).setChild(button, 0, (String)null, null);
  }

  private Server getServer()
  {
    final Server[] reply = new Server[1];
    String page = ServerContextFactory.get().getContextPath() + "/gi/reverse.html";
    Browser.withPage(page, new Runnable()
    {
      public void run()
      {
        reply[0] = GI.getServer("reverse");
      }

    });
    return reply[0];
  }
}